/**
 * 棋盘信息
 *
 * 构造函数中做一些初始化工作
 * 1. 重写构造函数==次构造函数代码块中做初始化工作
 * constructor(age:Int){
 *         //initialize
 * }
 *
 * 2. 如果没有次构造函数，只有主构造函数，又需要再构造时做一些初始化操作
 *    那么再init代码块中实现
 *    init{
 *         //initialize
 *     }
 */
class KGobangBoard{
    init{
        //initialize
        refreshBoard()
    }

    fun refreshBoard(){
        print("  ")
        for (i in 1..COLS){
            print("$i ")
        }
        println()
        for (i in 0..<ROWS){
            print("${i+1} ")
            for (j in 0..<COLS){
                print("${BoardData.boards[i][j]} ")
            }
            println()
        }
    }

    fun placeChess(location:KLocation,player:KPlayer):Boolean {
        val row = location.row -1
        val col = location.col -1
        //1. 判断是否越界了
        if (row !in 0..<ROWS || col !in 0..<COLS) {
            println("落子位置不在棋盘内！")
            return false
        }
        //2. 判断是否重复放置
        if (BoardData.boards[row][col] != "+") {
            println("重复落子！")
            return false
        }
        //3. 落子
        BoardData.boards[row][col] = player.getChess()
        refreshBoard()
        return true
    }
}







